package br.com.felix.fwt.ui;

import java.io.PrintWriter;

import br.com.felix.fwt.ui.css.Style;
import br.com.felix.fwt.ui.exception.ComponentRenderException;
import br.com.felix.fwt.ui.javascript.JavascriptListener;

/**
 * The Class VerticalPanel is used to align components vertically.
 */
public class VerticalPanel extends Panel {

	private static final long serialVersionUID = -6087660177532830132L;

	/**
	 * The style that will be utilized by every row of the Vertical Panel.
	 * */
	private String rowStyle = null;
	
	
	/**
	 * Instantiates a new vertical panel.
	 */
	public VerticalPanel(){
		this.cssClass = "fwtverticalpanel";
	}
	
	
	/* (non-Javadoc)
	 * @see br.com.felix.fwt.ui.Panel#write(java.io.PrintWriter)
	 */
	@Override
	public void write(PrintWriter out) throws ComponentRenderException {
		if(!authorized()) return;
		out.write("\n<div class=\"");
		out.write(this.cssClass);
		out.write("\" ");

		out.write("id=\""); 
		out.write(getName());
		out.write("\" ");
		
		if(javascripts != null){
			for(JavascriptListener js: javascripts){
				out.write(js.script());
			}
		}
		if(style!=null){
			out.write(style);
		}
		out.write(">");
		if(childs!=null){
			for(BaseComponent child:childs){
				out.write("\n<div ");
				if(rowStyle!=null){
					out.write(rowStyle);
				}
				out.write(">");
				child.write(out);
				out.write("\n</div>");
			}
		}
		out.write("</div>");
	}
	
	
	public void setRowStyle(Style style){
		rowStyle = style.toString();
	}

}
